/*
 Source: ufxTrader.java
 Software Copyright: Hundsun Technologies Inc.
 System: UFX Future Demo (Asynchronous)
 Module: Main Function
 Describition:
 This class is the main class for future demo, the documents for function description and Java programming helper can be found at ufx 
 website: https://ufx.hscloud.cn/ufx/html/doc/index.html
 Function id include: 819706 ,819707,819709,819710,819711,620001-33101
 author: Kai Zhan
 Date:2016/05/12
 Others:
 This demo is a sample for using Hundsun UFX System, we are highly not recommand any user to use this demo at any real market，for more details 
 please read <T2SDK JAVA Developer Manual>
 */
package com.hmkj.core.api.ufx.call;

import com.hmkj.boot.utils.SpringContextUtils;
import com.hmkj.core.api.ufx.mc.UFXMC;
import com.hmkj.core.api.ufx.trade.UfxTradeSync;
import com.hmkj.core.constant.ConfigNID;
import com.hmkj.core.service.cache.RedisService;
import com.hundsun.mcapi.MCServers;
import com.hundsun.t2sdk.impl.client.T2Services;
import lombok.extern.slf4j.Slf4j;

/**
 * 期货交易相关请求实例
 */
@Slf4j
public class TransactionCall {

    private static T2Services server = T2Services.getInstance();//T2实例化

    private static UFXMC ufxmc = new UFXMC();

    private static UfxTradeSync ufxTradeSync = new UfxTradeSync();

    private static TransactionCall transactionCall = new TransactionCall();

    private static String SENDER; // 客户编号

    private static int ORG_OTC;// 外盘期货机构编号

    private static int ORG_NATIVE;// 内盘期货机构编号

    private TransactionCall() {

    }


    public static TransactionCall getInstance() {
//        RedisService redisService = SpringContextUtils.getBean("redisService");
//        SENDER = redisService.get(ConfigNID.API_SENDER);
//        ORG_OTC = redisService.get(ConfigNID.API_ORG_OTC, Integer.class);
//        ORG_NATIVE = redisService.get(ConfigNID.API_ORG_NATIVE, Integer.class);
        return transactionCall;
    }


    /**
     * 获取T2SDK配置文件中配置的连接
     * 启动T2SDK，只需要在服务器启动时调用一次就可以了
     */
    public void initT2() throws Exception {
        server.setT2sdkConfigString("classpath:config/t2sdk_hundsun_trade-config.xml");//配置文件路径
        server.init();
        server.start();
        MCServers.MCInit();
    }

    /**
     * 外盘交易主推订阅（委托回报、成交回报）
     *
     * @param accountNo 资金账户
     */
    public void reqFunctionTradeOut(String accountNo) {
        ufxmc.reqFunctionTradeOut(accountNo);
    }

    /**
     * 内盘交易主推订阅（委托回报、成交回报）
     *
     * @param accountNo 资金账户
     */
    public void reqFunctionTradeIn(String accountNo) {
        ufxmc.reqFunctionTradeIn(accountNo);
    }


}
